package br.dimap.ppgsc.fmapn.util;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import br.fmapn.analyzer.FacadeBusinessProcessFrameworkRemote;

/*
import javax.naming.InitialContext;
import javax.naming.NamingException;

import br.fmapn.analyzer.FacadeBusinessProcessFrameworkRemote;
import br.fmapn.register.BusinessProcessServicesRemote;

*/
/**
 * 
 * @author marilia
 *
 */

public class GerenciadorLookup {

	private static FacadeBusinessProcessFrameworkRemote facadeBusinessProcessFramework;
	
	private static InitialContext initialContext;
	
	public GerenciadorLookup() {
		try {
			initialContext = new InitialContext();
		} catch (NamingException e) {
			e.printStackTrace();
		}
	}
	
	private static Object getContextLookup(String lookup) {
		Object bean = null;
		if (initialContext == null) {
			try {
				initialContext = new InitialContext();
			} catch (NamingException e) {
				e.printStackTrace();
			}
		}
		try {
			bean = initialContext.lookup(lookup);
		} catch (NamingException e) {
			e.printStackTrace();
		}

		return bean;
	}
	
	public static FacadeBusinessProcessFrameworkRemote obterFacadeBusinessProcessFramework() {
		if (facadeBusinessProcessFramework == null) {
			facadeBusinessProcessFramework = (FacadeBusinessProcessFrameworkRemote) getContextLookup("FMAPN-ear/FacadeBusinessProcessFramework/remote");
		}
		return facadeBusinessProcessFramework;
	}

}
